//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class FontScheme : IOfficeXmlSerializable
    {
        private FontCollection majorFont;
        private FontCollection minorFont;
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public FontCollection MajorFont
        {
            get { return majorFont; }
            set { majorFont = value; }
        }

        public FontCollection MinorFont
        {
            get { return minorFont; }
            set { minorFont = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("fontScheme"))
            {
                Name = c.GetOptionalString("name");
                MajorFont = c.ReadElementAs<FontCollection>("majorFont");
                MinorFont = c.ReadElementAs<FontCollection>("minorFont");
                c.WarnIf("ext");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("fontScheme"))
            {
                c.SetOptionalString("name", Name); //\\optional?
                c.WriteElementAs(MajorFont, "majorFont");
                c.WriteElementAs(MinorFont, "minorFont");
                c.WarnIf("ext");
            }
        }

        #endregion

        internal FontCollectionIndex GetIndex(FontFamily f)
        {
            if (MajorFont.Latin == f)
                return FontCollectionIndex.Major;
            if (MinorFont.Latin == f)
                return FontCollectionIndex.Minor;
            return FontCollectionIndex.None;
        }
    }
}